﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Web.Security;
using WebSimplicity.Data.Helpers;

namespace WebSimplicity.Data
{
    public interface IApplication
    {
        Guid ApplicationId { get; }
        string ApplicationName{ get; }
        string LoweredApplicationName { get; }
        string Description { get; set; }
    }

    [MetadataType(typeof(IApplication))]
    partial class Application : IApplication
    {
        public Application()
        {
            this.ApplicationId = Guid.NewGuid();
            this.ApplicationName = ShortGuid.Encode(this.ApplicationId);
            this.LoweredApplicationName = this.ApplicationName.ToLower();
        }
        public void Create()
        {
            Entities db = new Entities(Config.GetConnection("Data.Model"));
            db.Applications.AddObject(this);
            db.SaveChanges();
        }
        public void Activate()
        {
            Membership.ApplicationName = this.ApplicationName;
        }
    }
    public static class Applications
    {
        public static void SetActive(string ApplicationName)
        {
            Membership.ApplicationName = ApplicationName;
        }
    }
}
